package com.satan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.satan.entity.SysRoleMenu;
import com.satan.mapper.SysRoleMenuMapper;
import com.satan.service.SysRoleMenuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* @author Demon
* @description 针对表【sys_role_menu】的数据库操作Service实现
* @createDate 2023-10-03 20:53:34
*/
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu>
    implements SysRoleMenuService{

    @Override
    @Transactional
    public boolean updateMenus(Long id, Long[] menuIds) {
        boolean b1 = remove(new QueryWrapper<SysRoleMenu>().eq("role_id", id));
        List<SysRoleMenu> sysRoleMenuList=new ArrayList<>();
        Arrays.stream(menuIds).forEach(menuId->{
            SysRoleMenu roleMenu=new SysRoleMenu();
            roleMenu.setRoleId(id);
            roleMenu.setMenuId(menuId);
            sysRoleMenuList.add(roleMenu);
        });
        boolean b2 = saveBatch(sysRoleMenuList);
        return b1&&b2;
    }
}




